﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace LiteBlog.Common.Components
{
    public enum UrlType
    {
        Home,
        Post,
        Page,
        Category,
        Archive,
        Tag
    }
    public class UrlHelper
    {
        public static string Site
        {
            get
            {
                return HttpContext.Current.Request.Url.Host;
            }
        }

        public static string AppUrl
        {
            get
            {
                var url = HttpContext.Current.Request.Url;
                var http = url.Scheme; // http
                var authority = url.Authority; // host:port
                var appPath = HttpContext.Current.Request.ApplicationPath;
                var appUrl = string.Format("{0}://{1}{2}", http, authority, appPath);
                if (!appPath.Equals(@"/"))
                    appUrl += "/";
                return appUrl;
            }
        }

        public static string GetUrl(UrlType urlType, string id)
        {
            switch (urlType)
            {
                case UrlType.Home:
                    return AppUrl;
                case UrlType.Post:
                    return AppUrl + "Post/" + id;
                case UrlType.Category:
                    return AppUrl + id;
                case UrlType.Page:
                    return AppUrl + "Page/" + id;
                case UrlType.Tag:
                    return AppUrl + "Tag/" + id;
                case UrlType.Archive:
                    return AppUrl + id; // id == Year/Month
                default:
                    return string.Empty;
            }
        }
    }
}
